{% extends 'base.html' %}

{% block title %} {{ task.name.value }} {% endblock %}
{% block include %} 
	{{ task.media }} 
	<script>
		$(function() {
			initTask();
		});
	</script>
{% endblock %}

{% block content %}

<h3> 
	{% if editable %}
		Edit
	{% elif deletable %}
		Delete
	{% else %}
		View 
	{% endif %}
	Task: {{ task.name.value }}
</h3>

{% if editable %}
	<form method='post'> {% csrf_token %}
{% elif deletable %}
	<form method='post'> {% csrf_token %}

{% else %}
	<form>
{% endif %}

<fieldset name="task">
	
		{{ task.non_field_errors }}
		{{ task.name.errors }}
		<p> <label for="id_name" class='required'> Name: </label> {{ task.name }} </p>
		{{ task.project.errors }}
		<p> <label for="id_project" class='required'> Project: </label> {{ task.project }} </p>
		{{ task.sprint.errors }}
		<p> <label for="id_sprint"> Sprint: </label> {{ task.sprint }} </p>
		{{ task.type.errors }}
		<p> <label for="id_type" class='required'> Type: </label> {{ task.type }} </p>
		{{ task.parent.errors }}
		<p> <label for="id_parent"> Parent: </label> {{ task.parent }} </p>
		{{ task.priority.errors }}
		<p> <label for="id_priority" class='required'> Priority: </label> {{ task.priority }} </p>
		{{ task.status.errors }}
		<p> <label for="id_status" class='required'> Status: </label> {{ task.status }} </p>
		{{ task.description.errors }}
		<p> <label name="desc" for="id_description" class='required'> Description: </label> {{ task.description }} </p>
		{{ task.estimatedHours.errors }}
		<p> <label for="id_estimatedHours" class='required'> Estimated Hours: </label> {{ task.estimatedHours }} </p>
		{{ task.workedHours.errors }}
		<p> <label for="id_workedHours" class='required'> Worked Hours: </label> {{ task.workedHours }} </p>
		{{ task.users.errors }}
		<p> <label for="id_users"> Users: </label> </p>
	
	<div>{{ task.users }}</div>
	<div style="clear:both;" />
	
	<p> <label> Revisions: </label> </p>
	<div id='revision_list'> </div>
	<div id="select_revision" style="display:none;">
		{% include 'revisions.html' with is_task="true" tid=id %}
	</div>
	<div style='display:none;'> {{ task.revisions }} </div>
	<p><button id="add_revisions" type="button" {%if not editable %} disabled="True" {% endif %}>Add Revision</button></p>

	{% if children %}
	<p> <label> Sub Tasks: </label> </p>
	<div>
		<table class="data-table"><tbody>
			<tr> <th>Name</th> <th>Sprint</th> <th>Type</th> <th>Status</th> <th>Priority</th> <th>View</th> <th>Edit</th> </tr>
			{% for child in children %}
				<tr class={% cycle '' 'alt' %}> 
					<td>{{child.name}}</td> 
					<td> {% if child.sprint == None %} - {% else %} <a href='/sprint/view/{{ child.sprint.pk }}'> {{ child.sprint }} </a> {% endif %} </td>
					<td>{{child.type}}</td> 
					<td>{{child.status}}</td> 
					<td>{{child.priority}}</td>
					<td> <a href='/task/view/{{child.pk}}/'> View</a> </td>
					<td> <a href='/task/edit/{{child.pk}}/'> Edit</a> </td>
				</tr>
			{% endfor %}
		</tbody></table>
	</div>
	{% endif %}
</div>
</fieldset>

{% if editable %}

	<input type='submit' value='Save'>	
	</form>
	<form action='/tasks/' method="get">
    <input type="submit" value="Back" />
    </form>
{% elif deletable %}
	
	<input type='submit' value='Delete'>
	</form>
    <form action='/tasks/' method="get">
    <input type="submit" value="Back" />
    </form>

{% else %}
	</form>
	<form action="/task/edit/{{ id }}/" method="get">
	<input type="submit" value="Edit"/>
	</form>
    <form action='/tasks/' method="get">
    <input type="submit" value="Back" />
    </form>
{% endif %}
<h4>
Comments:
</h4>
{% include "comment.html" %}
{% endblock %}
